package org.zjh.controller.listener;

import org.zjh.constant.GameConstant;
import org.zjh.controller.GameController;
import org.zjh.model.ComputerA;
import org.zjh.model.ComputerB;
import org.zjh.model.ComputerPlayer;
import org.zjh.model.RealPlayer;
import org.zjh.utils.RandomUtil;
import org.zjh.view.game.GameFrame;
import org.zjh.view.ui.GameUi;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @description: 快速开始游戏按钮监听
 * @author 郑佳豪
 * @date 2024/10/22 14:23
 * @version 1.0
 */
public class QuickStartGameJbtLis extends MouseAdapter {


    @Override
    public void mouseClicked(MouseEvent e) {
        GameController gameController = GameController.getInstance();
        //创建 游客临时账户
        gameController.setPlayer(new RealPlayer("游客",null,null,GameConstant.DEFAULT_SCORE));
        //创建电脑玩家A 并随机赋值名字
        ComputerPlayer computerA = new ComputerA(GameConstant.COMPUTER_NAMES[RandomUtil.RANDOM.nextInt(GameConstant.COMPUTER_NAMES.length)],GameConstant.DEFAULT_SCORE);
        //创建电脑玩家B 并随机赋值名字
        ComputerPlayer computerB = new ComputerB(GameConstant.COMPUTER_NAMES[RandomUtil.RANDOM.nextInt(GameConstant.COMPUTER_NAMES.length)],GameConstant.DEFAULT_SCORE);
        //建立 轮询机制
        computerA.setNextPlayer(gameController.getPlayer());
        gameController.getPlayer().setNextPlayer(computerB);
        computerB.setNextPlayer(computerA);
        //设置电脑玩家
        gameController.setComputerA(computerA);
        gameController.setComputerB(computerB);
        gameController.setCurrentPlayer(computerA);

        //创建游戏窗口
        GameUi.gameFrame = new GameFrame();
    }
}
